package cn.south.campus.admin.sys.controller;

import cn.south.campus.admin.sys.model.req.SysUserReq;
import cn.south.campus.admin.sys.model.vo.SysUserVo;
import cn.south.campus.admin.sys.service.SysUserService;
import cn.south.campus.common.model.bo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2024/10/31 13:24
 */
@RestController
@RequestMapping("admin/user")
@AllArgsConstructor
public class SysUserController {


    private final SysUserService sysUserService;
    /**
     * 列表分页
     *
     * @param req query
     * @return IPage<SysUser>
     */
    @GetMapping("/page")
    public Result<IPage<SysUserVo>> page(SysUserReq req) {
        return Result.success(sysUserService.sysUserPage(req));
    }


    /**
     * 新增
     *
     * @param sysUser sysUser
     */
    @PostMapping("/add")
    public Result<Void> add(@RequestBody SysUserVo sysUser) {
        sysUserService.add(sysUser);
        return Result.success();
    }

    /**
     * 删除
     *
     * @param id ids
     */
    @DeleteMapping("/delete/{id}")
    public Result<Void> delete(@PathVariable Long id) {
        sysUserService.delete(id);
        return Result.success();
    }

    /**
     * 更新
     *
     * @param req sysUser
     */
    @PutMapping("/update")
    public Result<Void> update(@RequestBody SysUserVo req) {
        sysUserService.updateSysUser(req);
        return Result.success();
    }

    /**
     * 详情
     *
     * @param id id
     * @return SysUser
     */
    @GetMapping("/detail/{id}")
    public Result<SysUserVo> detail(@PathVariable Long id) {
        return Result.success(sysUserService.detail(id));
    }

}
